* This file creates a report on the perpetrator composition of the multiple imputed datasets 

global name "s2_desc_mi"
global main "C:/Users/silvio/Documents/CVR/ryp"
global output "$main/output"  
global data "${main}/data"  
global odata "${data}/Intermuestra1-2"  
global excel "${main}/excel"  

global code "${main}/code"  
global coord "$data/coordinates"  
global geocoord "$data/geocoord"  

cd $main
capture log close
log using "${output}/${name}.log", replace
clear

use "${data}/mult_impu", clear
set matsize 1392

la var perpe "Perpetrator"
label def perpel 1 "EST"  2 "SLU" 3 "OTH"
label values perpe perpel


reshape long y, i(n) j(mi)

sort perpe
by perpe: g ysum=sum(y)
by perpe: keep if _n==_N
replace ysum=ysum/20
g ysumrel=100*ysum/(ysum[1]+ysum[2]+ysum[3])
g ysumtot=ysum[1]+ysum[2]+ysum[3]
list perpe ysum ysumtot ysumrel 

export excel perpe ysum ysumtot ysumrel using "$excel/${name}.xls", sheet("res") sheetmodify firstrow(varlabels) missing(".")

clear
capture log close
